package org.updateNew;
import java.awt.Graphics;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import org.come.until.CutButtonImage;

import com.tool.tcp.GetTcpPath;
import com.tool.tcp.SpriteFactory;
import com.updateNew.MyJFrame;

public class UpdateNewFile {
	
	
	

    /**
     * 说明：根据指定URL将文件下载到指定目标位置
     *
     * @param urlPath
     *            下载路径
     * @param downloadDir
     *            文件存放目录
     * @return 返回下载文件
     */
    @SuppressWarnings("finally")
    public static File downloadFile1(String urlPath, String downloadDir) {
    	
    	// img/w1131,h603px.png
        File file = null;
        try {
            // 统一资源
            URL url = new URL(urlPath);
            // 连接类的父类，抽象类
            URLConnection urlConnection = url.openConnection();
            // http的连接类
            HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
            //设置超时
            httpURLConnection.setConnectTimeout(1000*5);
            //设置请求方式，默认是GET
            httpURLConnection.setRequestMethod("GET");
            // 设置字符编码
            httpURLConnection.setRequestProperty("Charset", "UTF-8");
            // 打开到此 URL引用的资源的通信链接（如果尚未建立这样的连接）。
            httpURLConnection.connect();
            // 文件大小
            int fileLength = httpURLConnection.getContentLength();

            // 控制台打印文件大小
            //system.out.println("您要下载的文件大小为:" + fileLength / (1024 * 1024) + "MB");

            // 建立链接从请求中获取数据
            URLConnection con = url.openConnection();
            BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
            // 指定文件名称(有需求可以自定义)
            String fileFullName = "ifupdateOld.txt";
            // 指定存放位置(有需求可以自定义)
            String path = downloadDir + File.separatorChar + fileFullName;
            file = new File(path);
            // 校验文件夹目录是否存在，不存在就创建一个目录
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }

            OutputStream out = new FileOutputStream(file);
            int size = 0;
            int len = 0;
            byte[] buf = new byte[2048];
            while ((size = bin.read(buf)) != -1) {
                len += size;
                out.write(buf, 0, size);
                // 控制台打印文件下载的百分比情况
                //system.out.println("下载了-------> " + len * 100 / fileLength + "%\n");
            }
            // 关闭资源
            bin.close();
            out.close();
            //system.out.println("文件下载成功！");
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            //system.out.println("文件下载失败！");
        } finally {
            return file;
        }

    }
    /**
     * 说明：根据指定URL将文件下载到指定目标位置
     *
     * @param urlPath
     *            下载路径
     * @param downloadDir
     *            文件存放目录
     * @return 返回下载文件
     */
    @SuppressWarnings("finally")
    public static File downloadFile3(String urlPath, String downloadDir) {
    	File file = null;
    	try {
    		// 统一资源
    		URL url = new URL(urlPath);
    		// 连接类的父类，抽象类
    		URLConnection urlConnection = url.openConnection();
    		// http的连接类
    		HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
    		//设置超时
    		httpURLConnection.setConnectTimeout(1000*5);
    		//设置请求方式，默认是GET
    		httpURLConnection.setRequestMethod("GET");
    		// 设置字符编码
    		httpURLConnection.setRequestProperty("Charset", "UTF-8");
    		// 打开到此 URL引用的资源的通信链接（如果尚未建立这样的连接）。
    		httpURLConnection.connect();
    		// 建立链接从请求中获取数据
    		BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
    		// 指定文件名称(有需求可以自定义)
    		String fileFullName = "server.json";
    		// 指定存放位置(有需求可以自定义)
    		String path = downloadDir + File.separatorChar + fileFullName;
    		file = new File(path);
    		// 校验文件夹目录是否存在，不存在就创建一个目录
    		if (!file.getParentFile().exists()) {
    			file.getParentFile().mkdirs();
    		}
    		
    		OutputStream out = new FileOutputStream(file);
    		int size = 0;
    		int len = 0;
    		byte[] buf = new byte[2048];
    		while ((size = bin.read(buf)) != -1) {
    			len += size;
    			out.write(buf, 0, size);
    		}
    		// 关闭资源
    		bin.close();
    		out.close();
    		//system.out.println("文件下载成功！");
    	} catch (MalformedURLException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	} catch (IOException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    		//system.out.println("文件下载失败！");
    	} finally {
    		return file;
    	}
    	
    }
    
    
    /**
     * 说明：根据指定URL将文件下载到指定目标位置
     *
     * @param urlPath
     *            下载路径
     * @param downloadDir
     *            文件存放目录
     * @return 返回下载文件
     */
    @SuppressWarnings("finally")
    public static File downloadFile4(String urlPath, String downloadDir) {
    	File file = null;
    	try {
    		// 统一资源
    		URL url = new URL(urlPath);
    		// 连接类的父类，抽象类
    		URLConnection urlConnection = url.openConnection();
    		// http的连接类
    		HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
    		//设置超时
    		httpURLConnection.setConnectTimeout(1000*5);
    		//设置请求方式，默认是GET
    		httpURLConnection.setRequestMethod("GET");
    		// 设置字符编码
    		httpURLConnection.setRequestProperty("Charset", "UTF-8");
    		// 打开到此 URL引用的资源的通信链接（如果尚未建立这样的连接）。
    		httpURLConnection.connect();
    		// 建立链接从请求中获取数据
    		BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
    		// 指定文件名称(有需求可以自定义)
    		String fileFullName = "tcps.zip";
    		// 指定存放位置(有需求可以自定义)
    		String path = downloadDir + File.separatorChar + fileFullName;
    		file = new File(path);
    		// 校验文件夹目录是否存在，不存在就创建一个目录
    		if (!file.getParentFile().exists()) {
    			file.getParentFile().mkdirs();
    		}
    		
    		OutputStream out = new FileOutputStream(file);
    		int size = 0;
    		int len = 0;
    		byte[] buf = new byte[2048];
    		while ((size = bin.read(buf)) != -1) {
    			len += size;
    			out.write(buf, 0, size);
    		}
    		// 关闭资源
    		bin.close();
    		out.close();
    		//system.out.println("文件下载成功！");
    		
    		String ur = System.getProperty("user.dir");
//    		getZip(ur);
    		
    		
    		
    	} catch (MalformedURLException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	} catch (IOException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    		//system.out.println("文件下载失败！");
    	} finally {
    		return file;
    	}
    	
    }
    
    /**
     * 说明：根据指定URL将文件下载到指定目标位置
     *
     * @param urlPath
     *            下载路径
     * @param downloadDir
     *            文件存放目录
     * @return 返回下载文件
     */
    @SuppressWarnings("finally")
    public static File downloadFile5(String urlPath, String downloadDir) {
    	File file = null;
    	try {
    		// 统一资源
    		URL url = new URL(urlPath);
    		// 连接类的父类，抽象类
    		URLConnection urlConnection = url.openConnection();
    		// http的连接类
    		HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
    		//设置超时
    		httpURLConnection.setConnectTimeout(1000*5);
    		//设置请求方式，默认是GET
    		httpURLConnection.setRequestMethod("GET");
    		// 设置字符编码
    		httpURLConnection.setRequestProperty("Charset", "UTF-8");
    		// 打开到此 URL引用的资源的通信链接（如果尚未建立这样的连接）。
    		httpURLConnection.connect();
    		// 建立链接从请求中获取数据
    		BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
    		// 指定文件名称(有需求可以自定义)
    		String fileFullName = "material.zip";
    		// 指定存放位置(有需求可以自定义)
    		String path = downloadDir + File.separatorChar + fileFullName;
    		file = new File(path);
    		// 校验文件夹目录是否存在，不存在就创建一个目录
    		if (!file.getParentFile().exists()) {
    			file.getParentFile().mkdirs();
    		}
    		
    		OutputStream out = new FileOutputStream(file);
    		int size = 0;
    		int len = 0;
    		byte[] buf = new byte[2048];
    		while ((size = bin.read(buf)) != -1) {
    			len += size;
    			out.write(buf, 0, size);
    		}
    		// 关闭资源
    		bin.close();
    		out.close();
    		//system.out.println("文件下载成功！");
    		
    		String ur = System.getProperty("user.dir");
//    		getZip1(ur);
    		decompress(ur+"/skin/material.zip", ur+"/skin/");
    		
    	} catch (MalformedURLException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	} catch (IOException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    		//system.out.println("文件下载失败！");
    	} finally {
    		return file;
    	}
    	
    }
    
    /**
     * 说明：根据指定URL将文件下载到指定目标位置
     *
     * @param urlPath
     *            下载路径
     * @param downloadDir
     *            文件存放目录
     * @return 返回下载文件
     */
    @SuppressWarnings("finally")
    public static File downloadFile6(String urlPath, String downloadDir) {
    	File file = null;
    	try {
    		// 统一资源
    		URL url = new URL(urlPath);
    		// 连接类的父类，抽象类
    		URLConnection urlConnection = url.openConnection();
    		// http的连接类
    		HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
    		//设置超时
    		httpURLConnection.setConnectTimeout(1000*5);
    		//设置请求方式，默认是GET
    		httpURLConnection.setRequestMethod("GET");
    		// 设置字符编码
    		httpURLConnection.setRequestProperty("Charset", "UTF-8");
    		// 打开到此 URL引用的资源的通信链接（如果尚未建立这样的连接）。
    		httpURLConnection.connect();
    		// 建立链接从请求中获取数据
    		BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
    		// 指定文件名称(有需求可以自定义)
    		String fileFullName = "tcps.zip";
    		// 指定存放位置(有需求可以自定义)
    		String path = downloadDir + File.separatorChar + fileFullName;
    		file = new File(path);
    		// 校验文件夹目录是否存在，不存在就创建一个目录
    		if (!file.getParentFile().exists()) {
    			file.getParentFile().mkdirs();
    		}
    		
    		OutputStream out = new FileOutputStream(file);
    		int size = 0;
    		int len = 0;
    		byte[] buf = new byte[2048];
    		while ((size = bin.read(buf)) != -1) {
    			len += size;
    			out.write(buf, 0, size);
    		}
    		// 关闭资源
    		bin.close();
    		out.close();
    		//system.out.println("文件下载成功！");
    		
    		String ur = System.getProperty("user.dir");
//    		getZip2(ur);
    		
    		
    		
    	} catch (MalformedURLException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	} catch (IOException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    		//system.out.println("文件下载失败！");
    	} finally {
    		return file;
    	}
    	
    }
    
    /**
     * 说明：根据指定URL将文件下载到指定目标位置
     *
     * @param urlPath
     *            下载路径
     * @param downloadDir
     *            文件存放目录
     * @return 返回下载文件
     */
    @SuppressWarnings("finally")
    public static File downloadFile22(String urlPath, String downloadDir) {
    	new MyJFrame();
    	File file = null;
    	try {
    		// 统一资源
    		URL url = new URL(urlPath);
    		// 连接类的父类，抽象类
    		URLConnection urlConnection = url.openConnection();
    		// http的连接类
    		HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
    		//设置超时
    		httpURLConnection.setConnectTimeout(1000*5);
    		//设置请求方式，默认是GET
    		httpURLConnection.setRequestMethod("GET");
    		// 设置字符编码
    		httpURLConnection.setRequestProperty("Charset", "UTF-8");
    		// 打开到此 URL引用的资源的通信链接（如果尚未建立这样的连接）。
    		httpURLConnection.connect();
    		// 文件大小
    		int fileLength = httpURLConnection.getContentLength();
    		
    		// 控制台打印文件大小
    		//system.out.println("您要下载的文件大小为:" + fileLength / (1024 * 1024) + "MB");
    		
    		// 建立链接从请求中获取数据
    		URLConnection con = url.openConnection();
    		BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
    		// 指定文件名称(有需求可以自定义)
    		String fileFullName = "game.exe";
    		// 指定存放位置(有需求可以自定义)
    		String path = downloadDir + File.separatorChar + fileFullName;
    		file = new File(path);
    		// 校验文件夹目录是否存在，不存在就创建一个目录
    		if (!file.getParentFile().exists()) {
    			file.getParentFile().mkdirs();
    		}
    		
    		OutputStream out = new FileOutputStream(file);
    		int size = 0;
    		int len = 0;
    		byte[] buf = new byte[2048];
    		while ((size = bin.read(buf)) != -1) {
    			len += size;
    			out.write(buf, 0, size);
    			// 控制台打印文件下载的百分比情况
    			//system.out.println("下载了-------> " + len * 100 / fileLength + "%\n");
    		}
    		// 关闭资源
    		bin.close();
    		out.close();
    		//system.out.println("游戏更新成功！正在启动请稍后！！！");
    	} catch (MalformedURLException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	} catch (IOException e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    		//system.out.println("文件下载失败！");
    	} finally {
    		return file;
    	}
    	
    }

    
    
    

    /**
     * 更新登录器
     *
     * @param
     */
    public static void updateNewexe(String ip) {
    	String in = "";
    	String inOld = "";
		String ur = System.getProperty("user.dir");
//		downloadFile1("http://"+ip+":8083/updateNewFile/ifupdate.txt", ur+"/resource/TXT/");//获取版本
		downloadFile3("http://"+ip+":8083/updateNewFile/server.json", ur);//获取区服
//		downloadFile4("http://"+ip+":8083/updateNewFile/img.zip", ur+"/img/xy2uiimg/");//获取图片
//		downloadFile4("http://"+ip+":8083/updateNewFile/img.zip", ur+"/resource/FightingSkill/");//获取图片
//		downloadFile5("http://"+ip+":8083/updateNewFile/material.zip", ur+"/skin/");//获取素材
		String filePath = ur+"/resource/TXT/ifupdate.txt";
		String filePathOld = ur+"/resource/TXT/ifupdateOld.txt";

		FileInputStream fin = null;
		FileInputStream finOld = null;
		try {
			fin = new FileInputStream(filePath);
			finOld = new FileInputStream(filePathOld);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		InputStreamReader reader = new InputStreamReader(fin);
		BufferedReader buffReader = new BufferedReader(reader);
		InputStreamReader readerOld = new InputStreamReader(finOld);
		BufferedReader buffReaderOld = new BufferedReader(readerOld);
		String strTmp = "";
		try {
			while((strTmp = buffReader.readLine())!=null){
				in = strTmp;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			buffReader.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String strTmpOld = "";
		try {
			while((strTmpOld = buffReaderOld.readLine())!=null){
//				//system.out.println(strTmpOld);
				inOld = strTmpOld;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			buffReaderOld.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(!in.equals(inOld)) {
			//如果不是最新版本  更新素材
//			downloadFile5("http://"+ip+":8083/updateNewFile/material.zip", ur+"/skin/");//获取素材

//				MyJFrame.downloadFile2("http://"+ip+":8083/updateNewFile/game.exe", ur);
//			downloadFile4("http://"+ip+":8083/updateNewFile/tcps.zip", ur+"/resource/FightingSkill/");//获取图片
//			downloadFile6("http://"+ip+":8083/updateNewFile/tcps.zip", ur+"/resource/FightingSkillFull/");//获取图片
			
			try {
				updateName2(ur+"/resource/TXT/ifupdateOld.txt");
				System.err.println("启动登录器");
				Runtime.getRuntime().exec(ur+"/gatU.bat");
				System.exit(0);
			} catch (IOException e) {
//				e.printStackTrace();
			}
			
			File file = null;
			  FileWriter fw = null;
			  file = new File(filePathOld);
			  try {
			   if (!file.exists()) {
			    file.createNewFile();
			   }
			   fw = new FileWriter(file);
			   fw.write(in);//向文件中写内容
			   fw.flush();
			  } catch (IOException e) {
			   // TODO Auto-generated catch block
			   e.printStackTrace();
			  }finally{
			   if(fw != null){
			    try {
			     fw.close();
			    } catch (IOException e) {
			     // TODO Auto-generated catch block
			     e.printStackTrace();
			    }
			   }
			  }
			deleteFile(filePathOld);
		}else {
			deleteFile(filePathOld);
		}
    }
    
    
    /**
     * 删除单个文件
     *
     * @param fileName
     *            要删除的文件的文件名
     * @return 单个文件删除成功返回true，否则返回false
     */
    public static boolean deleteFile(String fileName) {
        File file = new File(fileName);
        // 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
        if (file.exists() && file.isFile()) {
            if (file.delete()) {
                //system.out.println("删除单个文件" + fileName + "成功！");
                return true;
            } else {
                //system.out.println("删除单个文件" + fileName + "失败！");
                return false;
            }
        } else {
            //system.out.println("删除单个文件失败：" + fileName + "不存在！");
            return false;
        }
    }
    
    
 // 删除zip 文件
    public static void delZipFile(String url){
        File file=new File(url);
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File f : files) {
                if (f.getName().endsWith(".zip")) {  // zip文件  判断 是否存在
                  if(f.delete()) {
                	  //system.out.println("zip文件已经删除");
                  }else{
                	  //system.out.println("zip文件删除失败");
                  }
                }
            }
        }
    }
    /**
     * zip压缩文 解压
     */
    @SuppressWarnings("resource")
	public static void getZip(String url) throws IOException {
    	String urlfile = url+"/resource/FightingSkill/tcps.zip";
        //读取压缩文件
        ZipInputStream in = new ZipInputStream(new FileInputStream(urlfile),Charset.forName("GBK"));
        //zip文件实体类
        ZipEntry entry;
        //遍历压缩文件内部 文件数量
        while((entry = in.getNextEntry()) != null){
            if(!entry.isDirectory()){
                //文件输出流
                FileOutputStream out = new FileOutputStream( url+"/resource/FightingSkill/"+entry.getName());
                BufferedOutputStream bos = new BufferedOutputStream(out);
                int len;
                byte[] buf = new byte[1024];
                while ((len = in.read(buf)) != -1) {
                    bos.write(buf, 0, len);
                }
                // 关流顺序，先打开的后关闭
                bos.close();
                out.close();
                try {
					Thread.sleep(1500);
					delZipFile(url+"/resource/FightingSkill/");
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        }
    }
    
    /**
     * zip压缩文 解压
     */
    @SuppressWarnings("resource")
	public static void getZip2(String url) throws IOException {
    	String urlfile = url+"/resource/FightingSkillFull/tcps.zip";
        //读取压缩文件
        ZipInputStream in = new ZipInputStream(new FileInputStream(urlfile),Charset.forName("GBK"));
        //zip文件实体类
        ZipEntry entry;
        //遍历压缩文件内部 文件数量
        while((entry = in.getNextEntry()) != null){
            if(!entry.isDirectory()){
                //文件输出流
                FileOutputStream out = new FileOutputStream( url+"/resource/FightingSkillFull/"+entry.getName());
                BufferedOutputStream bos = new BufferedOutputStream(out);
                int len;
                byte[] buf = new byte[1024];
                while ((len = in.read(buf)) != -1) {
                    bos.write(buf, 0, len);
                }
                // 关流顺序，先打开的后关闭
                bos.close();
                out.close();
                try {
					Thread.sleep(1500);
					delZipFile(url+"/resource/FightingSkillFull/");
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        }
    }
    
    /**
     * zip压缩文 解压
     */
    @SuppressWarnings("resource")
	public static void getZip1(String url) throws IOException {
    	String urlfile = url+"/skin/material.zip";
        //读取压缩文件
        ZipInputStream in = new ZipInputStream(new FileInputStream(urlfile),Charset.forName("GBK"));
        //zip文件实体类
        ZipEntry entry;
        //遍历压缩文件内部 文件数量
        while((entry = in.getNextEntry()) != null){
            if(!entry.isDirectory()){
                //文件输出流
                FileOutputStream out = new FileOutputStream( url+"/skin/"+entry.getName());
                BufferedOutputStream bos = new BufferedOutputStream(out);
                int len;
                byte[] buf = new byte[1024];
                while ((len = in.read(buf)) != -1) {
                    bos.write(buf, 0, len);
                }
                // 关流顺序，先打开的后关闭
                bos.close();
                out.close();
                try {
					Thread.sleep(1500);
					delZipFile(url+"/skin/");
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
        }
    }
    
    
    @SuppressWarnings("rawtypes")
	public static void decompress(String zipFile , String dstPath)throws IOException{
        File pathFile = new File(dstPath);
        if(!pathFile.exists()){
            pathFile.mkdirs();
        }
        ZipFile zip = new ZipFile(zipFile);
        for(Enumeration entries = zip.entries();entries.hasMoreElements();){
            ZipEntry entry = (ZipEntry)entries.nextElement();
            String zipEntryName = entry.getName();
            InputStream in = null;
            OutputStream out = null;
            try{
                in =  zip.getInputStream(entry);
                String outPath = (dstPath+"/"+zipEntryName).replaceAll("\\*", "/");;
                //判断路径是否存在,不存在则创建文件路径
                File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
                if(!file.exists()){
                    file.mkdirs();
                }
                //判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
                if(new File(outPath).isDirectory()){
                    continue;
                }

                out = new FileOutputStream(outPath);
                byte[] buf1 = new byte[1024];
                int len;
                while((len=in.read(buf1))>0){
                    out.write(buf1,0,len);
                }
            }
            finally {
                if(null != in){
                    in.close();
                }

                if(null != out){
                    out.close();
                }
           }
        }
        zip.close();
        delZipFile(dstPath);
    }
    
    public static void updateName2(String url) throws IOException {
	     File oldFile = new File(url);
	     if(!oldFile.exists()) {
	    	 oldFile.createNewFile();
	     }
	     String ur = System.getProperty("user.dir");
    	 deleteFile(ur+"/resource/TXT/ifupdate.txt");
	     //system.out.println("修改前文件名称是："+oldFile.getName());
	     String rootPath = oldFile.getParent();
	     //system.out.println("根路径是："+rootPath);
	     File newFile = new File(rootPath + File.separator + "/ifupdate.txt");
	     //system.out.println("修改后文件名称是："+newFile.getName());
	     if (oldFile.renameTo(newFile))  {
	    	 //system.out.println("修改成功!");
	     } else {
	    	 //system.out.println("修改失败");
	     }
    }
    
    /**
     * 测试
     *
     * @param args
     */
    public static void main(String[] args) {
        // 指定资源地址，下载文件测试
//    	downloadFile1("http://81.70.133.161:8083/GameServer/api/logout", "E:/soft/");
//    	String ip = "8.141.57.10";
//    	updateNewexe(ip);
//    	doGet("http://8.141.57.10:8083/GameServer/api/logout");
    }
    
}